package com.hl.sfzy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.entity.SysCompany;
import com.hl.sfzy.mapper.SysCompanyMapper;
import com.hl.sfzy.service.SyscompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("syscompanyService")
public class SysCompanyServiceImpl implements SyscompanyService {
    @Autowired
    private SysCompanyMapper sysCompanyMapper;
    @Override
    public int add(SysCompany entity) {
        return sysCompanyMapper.insert(entity);
    }

    @Override
    public int edit(SysCompany entity) {
        return sysCompanyMapper.update(entity);
    }

    @Override
    public int remove(Integer id) {
        return sysCompanyMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return sysCompanyMapper.deleteBatch(ids);
    }

    @Override
    public List<SysCompany> find(SysCompany entity) {
        return sysCompanyMapper.select(entity);
    }

    @Override
    public SysCompany findById(Integer id) {
        return sysCompanyMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, SysCompany entity) {

        //开启分页
        PageHelper.startPage(pageNum, pageSize);
        //当前页数据
        List<SysCompany> list = sysCompanyMapper.select(entity);
        //分页信息对象
        PageInfo<SysCompany> pageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();

        //map存储当前页数据、总页数、总记录数
        map.put(CommonConstant.PAGE_LIST,list);
        map.put(CommonConstant.PAGE_TOTAL,pageInfo.getPages());
        map.put(CommonConstant.TOTAL,pageInfo.getTotal());

        return map;
    }

    @Override
    public SysCompany selectByCompanyname(String companyname) {
        return sysCompanyMapper.selectByCompanyname(companyname);
    }

    @Override
    public int findCount() {
        return sysCompanyMapper.selectCount();
    }
}
